package database

import (
	"github.com/influxdata/influxdb-client-go/v2"
	"github.com/influxdata/influxdb-client-go/v2/api"
)

type InfluxDB struct {
	client influxdb2.Client
	org    string
	bucket string
}

func NewInfluxDB(url, org string) (*InfluxDB, error) {
	client := influxdb2.NewClient(url, "")
	return &InfluxDB{
		client: client,
		org:    org,
		bucket: "saasems",
	}, nil
}

func (db *InfluxDB) GetDB() api.WriteAPI {
	return db.client.WriteAPI(db.org, db.bucket)
}

func (db *InfluxDB) Close() {
	db.client.Close()
}
